<?php
namespace controller;

use service\DataService;
use think\Controller;
use think\db\Query;
use think\Db;

/**
 * 网站前台基础控制器
 * Class BasicIndex
 * @package controller
 */
class BasicIndex extends Controller
{
    /**
     * 初始化方法
     */
    public function _initialize()
    {
        // 当前完整URL地址
        $this->url = $this->request->url(true);
        // 获取分类菜单
        $this->assign('navs', self::nav());
    }

    /**
     * 导航列表
     *
     * @return void
     * @author leo.lei(346991581@qq.com)
     */
    protected function nav()
    {
        $list = Db::name('YogaCategory')->where(['status'=>1,'pid'=>0,'is_deleted'=>0])->field('id,title,url')->order('sort asc,id asc')->select();
        foreach ((array)$list as $k => $v) {
            $list[$k]['sub'] = Db::name('YogaCategory')->where(['status'=>1,'pid'=>$v['id'],'is_deleted'=>0])->field('id,title,url')->order('sort asc,id asc')->select();
        }
        return $list;
    }
}
